package com.industrial.im.controller;

import com.industrial.common.core.utils.DateUtils;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.im.factory.SmsSendFactory;
import com.industrial.im.service.SmsSenderService;
import com.industrial.im.utils.EmailSendUtils;
import com.industrial.im.utils.SmsSendUtils;
import com.industrial.im.vo.SendEmailVo;
import com.industrial.im.vo.SendSmsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/chat/send")
public class ChatSendController extends BaseController {
    @Autowired
    private SmsSendUtils smsSendUtils;
    @Autowired
    private EmailSendUtils emailSendUtils;

    @Value("${aliyun.sms.sendTemplate}")
    private String template;


    @GetMapping("/sms")
    public AjaxResult sms(SendSmsVo sendSmsVo){
        Map map = new HashMap();
        map.put("time", DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD_HH_MM_SS));
        sendSmsVo.setTemplateCode(template);
        smsSendUtils.sendSms(map, sendSmsVo);
        return AjaxResult.success("发送成功");

    }

    @PostMapping("/email")
    public AjaxResult email(@RequestBody @Validated SendEmailVo sendEmailVo){
        emailSendUtils.sendEmail(sendEmailVo);
        return AjaxResult.success("发送成功");
    }


}
